<?php
/**
 * @version		1.0.1 audit
 * @author		PROinsurer
 * @website		www.proinsurer.com.ua
 */
defined('_JEXEC') or die('Restricted access'); 

// ШАПКА
include_once JPATH_COMPONENT .'/views/header.php';
?>

<div class="row">
<div class="span12">	
	<div class="tabbable tabs-left" >
		
      <? include_once JPATH_COMPONENT .'/views/left_1.php'; ?>
      
		<div class="tab-content">
			
         <? if (@$this->fcompar->compar) { ?>
         
		
	<div class="tab-pane active" id="tab2">
		<h2>Сопоставление полей по которым производить поиск</h2>
      <div class="alert alert-success">Найдено строк с данными: <b><?=$this->fcompar->compar->rows;?></b>. Дата загрузки: <b><?=$this->fcompar->date;?></b>. Имя файла: <b><?=$this->fcompar->name;?></b>.</div>
		<div class="row" style="margin-left: 10px;">
         <form>
         <div style="text-align:right; margin-bottom: 10px; margin-top:-15px;">
            <span id="compar_error" style="vertical-align: middle;color:red;"></span>
            <img id="compar_loading" src="/components/com_audit/assets/images/loading.gif" style="vertical-align: middle;display:none;">
            <input type="button" class="btn" pr_url="/private/audit?view=compar&no_html=1" pr_target="compar_error" onclick="return comparForm(this);" value="Обработать">
         </div>
      
         <input type="hidden" name="id" value="<?=$this->fcompar->id;?>">
         <input type="hidden" name="view" value="compar">
         <input type="hidden" name="no_html" value="1">
         <input type="hidden" name="task" value="compar_form">
			<!--<div class="span8">-->
			  <table class="table table-condensed tbl_compar">
				<thead>
				  <tr>
					<th width="3%">#</th>
					<th width="27%">Поле для БД</th>
               <th width="27%">Поле из файла</th>
					<th>Где производить поиск</th>
				  </tr>
				</thead>
				<tbody>
            
               <? foreach ($this->fstruct AS $key=>$rec) {    //$this->compar->compar->fields[$key] =  'err';  ?>

                  <tr>
					      <td><?=$rec->order;?></td>
                     <td><?=$rec->name;?><br><small><?=$rec->description;?></small></td>
                     <td>
                        <select name="fcompar_<?=$rec->id;?>" onChange="( (this.value=='err') ? $(this).next().css({'background-color':'#FF7B00'}) : ( (this.value=='skip') ? $(this).next().css({'background-color':'#676767'}) : $(this).next().css({'background-color':'transparent'}) ) );" autocomplete="off">
                           <option value="err" <?=( ($this->fcompar->compar->fields[$key]==='err') ? 'selected="selected"' : '' );?> style="background-color:#FFD000">--- не определенно ---</option>
                           <option value="skip" <?=( ($this->fcompar->compar->fields[$key]==='skip') ? 'selected="selected"' : '' );?> style="background-color:#E4E4E4">--- пропустить ---</option>
      							<optgroup label="Сделайте выбор">
                              <? foreach ($this->fcompar->compar->file AS $i=>$val) { ?>
      								   <option value="<?=$i;?>" <?=( ($this->fcompar->compar->fields[$rec->id]===$i) ? 'selected="selected"' : '' );?> ><?=$val;?></option>
                              <? } ?>
      							</optgroup>
      						</select> &nbsp; <span style="background-color:<?=( ($this->fcompar->compar->fields[$rec->id]==='err') ? '#FF7B00' : (($this->fcompar->compar->fields[$rec->id]==='skip') ? '#676767' : '') );?>;color:#FFF;padding:1px 6px;font-weight: bold;"> ! </span>
                     </td>
                     <td>
                        <input type="hidden" name="fident_<?=$rec->id;?>" value="">
                        <div class="btn-group dropdown">
							<a class="btn dropdown-toggle pull-right" data-toggle="dropdown" href="#" target_id="sprav_list" onClick="cur_row = <?=$rec->id;?>; showPropList(this);return false;"><i class="icon-plus"></i></a>
							
							<ul class="dropdown-menu pull-right ">
							 <? foreach ($this->spravlist AS $sl) { ?>
									  <li><a href="#" onClick="AddIdent('<?=$sl->val;?>','<?=$sl->name;?>'); return false;"><?=$sl->name;?></a></li>
								<? } ?>
							</ul>
						</div>
                     </td>
                  </tr>

               <? } ?>
               
				  
				</tbody>
			  </table>
			<!--</div>-->
         </form>
		</div>

	
	</div><!--/.tab2-->
			
		<? } else { ?>
      
      <div class="alert alert-block">
		<button type="button" class="close" data-dismiss="alert">×</button> 
		<h4>Внимание!</h4>
		Нет ни одного загруженного файла...
		</div>
      
      <? } ?>
			
    </div>
    </div>
</div>
</div>

   
      


<script>

var cur_row = 0;

function AddIdent(sprav,sname) {
   if (!cur_row) { alert('Error 151'); return false; }
   $inp = $('input[name="fident_'+cur_row+'"]');
   $inp.val( $inp.val()+','+sprav );
   $inp.parent().append('<span style="margin-left: 10px;" class="label label-success">'+sname+'&nbsp;<a onClick="RemIdent(this,'+cur_row+',\''+sprav+'\'); return false;" class="close" style="float: none;" chref="#">&times;</a></span>');
   
}

function RemIdent(obj,row,sprav) {
   $inp = $('input[name="fident_'+row+'"]');
   var val = $inp.val();
   val = val.replace(','+sprav,'');
   $inp.val( val );
   $(obj).parent().remove();
}

<? if (count($this->fcompar->compar->ident)) { ?>

   jQuery(document).ready(function(){
      <? foreach ($this->fcompar->compar->ident AS $i=>$val) { ?>
         cur_row = <?=$i;?>;
         <? foreach ($val AS $sprav) { ?>
            AddIdent('<?=$sprav;?>','<?=$this->slName[$sprav];?>');
         <? } ?>
      <? } ?>
      cur_row = 0;
   });

<? } else { ?>
   //alert('aaaaaaaaa');
<? } ?>
</script>

<?
   // -- ПОДВАЛ ----------------------------------------------------------------
   include_once JPATH_COMPONENT .'/views/futer.php';
?>

<?
   //  -- Файл с Окошками... ---------------------------------------------------
   include_once JPATH_COMPONENT .'/views/windows.php';
?>

<?
   //  -- Файл со Скриптами... -------------------------------------------------
   include_once JPATH_COMPONENT .'/views/default.js.php';
?>
